﻿Imports Microsoft.Win32

Module mdRegistry

    Public Function SetKeyUserName_Department(ByVal _username As String, ByVal _depart As Integer) As Boolean
        Try
            Dim rkey As RegistryKey
            rkey = Registry.LocalMachine.OpenSubKey("Software\Tan Dong Tien\{9B4778FA-089B-49E7-848C-DA55A460E3F3}", True)
            If IsNothing(rkey) Then
                rkey = Registry.LocalMachine.CreateSubKey("Software\Tan Dong Tien\{9B4778FA-089B-49E7-848C-DA55A460E3F3}")
            End If
            rkey.SetValue("UserName", _username)
            rkey.SetValue("Department", _depart)
            rkey.Close()
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function SetKeyUserName(ByVal _username As String) As Boolean
        Try
            Dim rkey As RegistryKey
            rkey = Registry.LocalMachine.OpenSubKey("Software\Tan Dong Tien\{9B4778FA-089B-49E7-848C-DA55A460E3F3}", True)
            If IsNothing(rkey) Then
                rkey = Registry.LocalMachine.CreateSubKey("Software\Tan Dong Tien\{9B4778FA-089B-49E7-848C-DA55A460E3F3}")
            End If
            rkey.SetValue("UserName", _username)
            rkey.Close()
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function


    Public Function GetValue_ROEDate() As Date
        Dim rkey As RegistryKey
        rkey = Registry.LocalMachine.OpenSubKey("Software\Tan Dong Tien\{9B4778FA-089B-49E7-848C-DA55A460E3F3}", True)
        If IsNothing(rkey.GetValue("ROEDate")) Or rkey.GetValue("ROEDate") <> (Now.Day & "/" & Now.Month & "/" & Now.Year) Then
            'Dim wROE As New frmRateOfExchange
            'wROE.ShowDialog()
            Return Now.Day & "/" & Now.Month & "/" & Now.Year
        End If
        Return rkey.GetValue("ROEDate")
    End Function

    Public Function GetValue_ROEValue() As String
        Dim rkey As RegistryKey
        rkey = Registry.LocalMachine.OpenSubKey("Software\Tan Dong Tien\{9B4778FA-089B-49E7-848C-DA55A460E3F3}", True)
        If IsNothing(rkey.GetValue("ROEValue")) Then
            'Dim wROE As New frmRateOfExchange
            'wROE.ShowDialog()
            Return "210000"
        End If
        Return rkey.GetValue("ROEValue")
    End Function

    Public Function GetValue_Username() As String
        Dim _username As String = ""
        Dim rkey As RegistryKey
        rkey = Registry.LocalMachine.OpenSubKey("Software\Tan Dong Tien\{9B4778FA-089B-49E7-848C-DA55A460E3F3}", True)
        If Not IsNothing(rkey) Then
            _username = rkey.GetValue("UserName")
            rkey.Close()
        End If
        Return _username
    End Function


End Module
